package com.woniuxy.carrental.controller;

import com.woniuxy.carrental.entity.PageBean;
import com.woniuxy.carrental.entity.RentCarInfo;
import com.woniuxy.carrental.entity.ResponseResult;
import com.woniuxy.carrental.service.RenrCarInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author author
 * @create 2021-10-02 22:03
 */


@RestController
public class RenrCarInfoServiceController {

    @Autowired
    RenrCarInfoService renrCarInfoService;

    @GetMapping("/getRentCarInfotwo")
    public List<RentCarInfo> getRentCarInfotwo(){
     return renrCarInfoService.getallRentCarInfo();
    }



    @GetMapping("/getRenrCarIn")
  public ResponseResult<PageBean<RentCarInfo>> getRenrCarIn(RentCarInfo rentCarInfo,int pageIndex,int pageSize){
        System.out.println("查询条件："+rentCarInfo);
        System.out.println("pageSize："+pageSize);
        System.out.println("pageIndex："+pageIndex);
        List<RentCarInfo> rentCarInfos = renrCarInfoService.selectAllRentCarInfo(rentCarInfo, pageIndex, pageSize);
        System.out.println(rentCarInfos);
        int i = renrCarInfoService.selectRentCarInfoCountBylimit(rentCarInfo);
        PageBean<RentCarInfo> pageBean=new PageBean();
        pageBean.setBeanList(rentCarInfos);
        pageBean.setPageIndex(pageSize);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(i);

        return new ResponseResult<PageBean<RentCarInfo>>(pageBean,200,"ok");
  }


    @PostMapping("/addRenrCarIn")
    public String addRenrCarIn(@RequestBody RentCarInfo rentCarInfo){
        System.out.println(rentCarInfo);
      renrCarInfoService.addRentCarInfo(rentCarInfo);
        return "添加成功";
    }


    @PutMapping("/updateRenrCarIn")
    public String updateRenrCarIn(@RequestBody RentCarInfo rentCarInfo){
        System.out.println(rentCarInfo);
        renrCarInfoService.updateRentCarInfo(rentCarInfo);
        return "修改成功";
    }

    @DeleteMapping("/deleteRenrCarIn/{rentcarid}")
    public String eletedRenrCarIn(@PathVariable ("rentcarid") int rentcarid){
        System.out.println(rentcarid);
        renrCarInfoService.delectRentCarInfoCountByid(rentcarid);
        return "删除成功";
    }


    @PutMapping("/updateRenrCarInbyrentcarid/{rentcarid}")
    public String updateRenrCarInbyrentcarid(@PathVariable ("rentcarid") int rentcarid){
        renrCarInfoService.updateStareByrentcarid(rentcarid);
        return "修改成功";
    }





}
